home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / modelers / geomview / source.lha / Geomview / src / bin / crayola / common / callbacks.c next >
C/C++ Source or Header  |  1993-03-02  |  4KB  |  184 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include "geom.h"
  4. #include "lisp.h"
  5. #include "pickfunc.h"
  6. #include "crayola.h"
  7. #include "ui.h"
  8.  
  9. Lake *lake;
  10.  
  11. static Geom *undoGeom = NULL;
  12. static char *undoID = NULL;
  13.  
  14. static char msg[] = "callbacks.c";
  15.  
  16. #define PICK_YES        "(interest (pick self))"
  17. #define PICK_NO            "(uninterest (pick self))"
  18.  
  19. void SetUndo(Geom *g, char *name) {
  20.   if (undoGeom != NULL) GeomDelete(undoGeom);
  21.   if (undoID != NULL) OOGLFree(undoID);
  22.   undoGeom = GeomCopy(g);
  23.   undoID = OOGLNewNE(char, strlen(name) + 1, msg);
  24.   strcpy(undoID, name);
  25. }
  26.  
  27. Geom *GetObject(char *name) {
  28.   printf("(echo \"{\")");
  29.   printf("(write geometry - %s bare)", name);
  30.   printf("(echo \"}\")");
  31.   fflush(stdout);
  32.   return GeomFLoad(stdin, NULL);
  33. }
  34.  
  35. Geom *GetTarget() {
  36.   return GetObject("targetgeom");
  37. }
  38.  
  39. void ReplaceObject(Geom *g, char *name) {
  40.   if (g == NULL) return;
  41.   printf("(geometry %s ", name);
  42.   GeomFSave(g, stdout, NULL);
  43.   printf(")");
  44.   printf("(redraw allcams)");
  45.   fflush(stdout);
  46. }
  47.  
  48. void ReplaceTarget(Geom *g) {
  49.   ReplaceObject(g, "targetgeom");
  50. }
  51.  
  52. void freeze() {
  53.   uiFreeze();
  54.   printf(PICK_NO);
  55.   fflush(stdout);
  56. }
  57.  
  58. void thaw() {
  59.   printf("(echo \"(ack)\\n\")");
  60.   fflush(stdout);
  61. }
  62.  
  63. LDEFINE(ack, LVOID,
  64.      "(ack)\n\
  65. Command sent back from Geomview indicating that everything has been\n\
  66. processed")
  67. {
  68.   LDECLARE(("ack", LBEGIN,
  69.         LEND));
  70.   printf(PICK_YES);
  71.   fflush(stdout);
  72.   uiThaw();
  73.   return Lt;
  74. }
  75.  
  76. DEFPICKFUNC("(pick COORDSYS GEOMID G V E F P VI EI FI)",
  77.         coordsys,
  78.         id,
  79.         point, pn,
  80.         vertex, vn,
  81.         edge, en,
  82.         face, fn, 10,
  83.         ppath, ppn, 50,
  84.         vi,
  85.         ei, ein,
  86.         fi,
  87. {
  88.   Geom *g;
  89.   ColorA color;
  90.   int setcolor = 0;
  91.   int vcolor;
  92.   int fcolor;  
  93.  
  94.   if (!pn) return Lt;
  95.   freeze();
  96.   g = GetObject(id);
  97.   if (uiSet() || uiSetAll()) {
  98.     if (crayHasColor(g, ppath)) {
  99.       setcolor = 1; 
  100.       vcolor = fcolor = 0;
  101.     }
  102.     else {
  103.       vcolor = crayCanUseVColor(g, ppath);
  104.       fcolor = crayCanUseFColor(g, ppath);
  105.       if ((vcolor || fcolor) && 
  106.       !uiQuery("Object currently has no color", 
  107.            "information.  Would you",
  108.            "like to add color information to it?", "yes", "no")) {
  109.     if (vcolor && fcolor) {
  110.       vcolor = uiQuery("Would you like to color the",
  111.                "object by face or", "by vertex?", 
  112.                "By Face", "By Vertex");
  113.       fcolor = vcolor ? 0 : 1;
  114.     }
  115.     setcolor = 1;
  116.       }
  117.     }
  118.     if (setcolor) {
  119.       uiCurrentColor(&color);
  120.       SetUndo(g, id);
  121.       if (vcolor) crayUseVColor(g, &crayDefColor, ppath);
  122.       else if (fcolor) crayUseFColor(g, &crayDefColor, ppath);
  123.       if (uiSetAll()) craySetColorAll(g, &color, ppath);
  124.       else craySetColorAt(g, &color, vi, fi, ei, ppath, &vertex);
  125.       ReplaceObject(g, id);
  126.     }
  127.   }
  128.   else if (uiGet() && crayGetColorAt(g, &color, vi, fi, ei, ppath, &vertex))
  129.     uiChangeColor(&color);
  130.   else if (uiEliminateColor()) {
  131.     SetUndo(g, id);
  132.     if (crayEliminateColor(g, ppath)) ReplaceObject(g, id);
  133.   }
  134.   GeomDelete(g);
  135.   thaw();
  136.   return Lt;
  137. })
  138.  
  139. void init() {
  140.        
  141.        crayolaInit();
  142.      
  143.      LInit();
  144.      LDefun("pick", Lpick, Hpick);
  145.      LDefun("ack", Lack, Hack);
  146.      lake = LakeDefine(stdin, stdout, NULL);
  147.      printf(PICK_YES);
  148.      fflush(stdout);
  149.  
  150.      uiChangeColor(&crayDefColor);
  151.  
  152. }
  153.  
  154. void dopipes() {
  155.   LObject *lit, *val;
  156.   lit = LSexpr(lake);
  157.   val = LEval(lit);
  158.   LFree(lit);
  159.   LFree(val);
  160. }
  161.  
  162. void checkpipes() {
  163.   if (async_fnextc(stdin, 0) != NODATA) dopipes();
  164.   else {
  165.     static struct timeval tenth = { 0, 100000 };
  166.     select(0, NULL, NULL, NULL, &tenth);
  167.   }
  168. }
  169.  
  170. int undo() {
  171.        if (undoGeom != NULL) {
  172.      ReplaceObject(undoGeom, undoID);
  173.      return 1;
  174.        } else return 0;
  175.    }
  176.      
  177.  
  178. void quit() {
  179.        if (undoGeom != NULL) GeomDelete(undoGeom);
  180.      if (undoID != NULL) OOGLFree(undoID);
  181.   exit(0);
  182. }
  183.  
  184.